#ifndef __CLIENT_COMMON_RECORD_included
#define __CLIENT_COMMON_RECORD_included

#include <vector>
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include "../port/System.h"

using namespace std;

namespace Client {
namespace Common {

class CDBCursor;

class CRecord : public boost::enable_shared_from_this<CRecord> {

	vector<string> mStringPool;

public :

	typedef rapidjson::Document JsonDocument;
	typedef rapidjson::Value JsonValue;
	typedef rapidjson::StringBuffer JsonBuffer;
	typedef rapidjson::Writer<rapidjson::StringBuffer> JsonWriter;

	int mIndex;

	CRecord() : mIndex(-1) { }
	CRecord(CDBCursor& c);

	virtual string& GetTableName() = 0;
	virtual void GetValueSet(map<std::string, string>& values) = 0;
	virtual void WriteJson(JsonWriter& writer) = 0;

	inline void SetValue(JsonValue& jv, string& v) {
		if(jv.IsString()) v = jv.GetString();
	}

	inline void SetValue(JsonValue& jv, int& v, int def = -1) {
		if(jv.IsInt()) v = jv.GetInt();
		else v = def;
	}

	inline void SetValue(JsonValue& jv, Util::CSystem::Int64& v, int def = -1) {
		if(jv.IsInt64()) v = jv.GetInt64();
		else v = def;
	}

	string& GetValueDesc(string& v);
	string& GetValueDesc(int v);
	string& GetValueDesc(Util::CSystem::Int64 v);


	static string& GetValueDesc(string& v, string& buf);
	static string& GetValueDesc(int v, string& buf);
	
};

typedef boost::shared_ptr<CRecord> RecordRef;

} // Common
} // Client

#endif //__CLIENT_COMMON_RECORD_included